/*
 * Copyright (c) 2008, Xiong Yingfei, the University of Tokyo
 * All rights reserved.
 */
package ac.jp.u_tokyo.SyncLib.language2;

import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import ac.jp.u_tokyo.SyncLib.language.EvaluationFailedException;
import ac.jp.u_tokyo.SyncLib.language.GraphCombinatorBody;
import ac.jp.u_tokyo.SyncLib.language.SyncBody;

public abstract class DGetExpr extends VarExpr
{
	Var _dict;
	Var _key;
	

	public DGetExpr(int line, Var dict, Var key)
	{
		super(line);
		_dict = dict;
		_key = key;
	}

	@Override
	public void addBody(Var var, boolean atLeft, GraphCombinatorBody body,
			Collection<String> genericParas) throws EvaluationFailedException
	{
		List<Var> paras = new LinkedList<Var>();
		paras.add(_key);
		paras.add(_dict);
		paras.add(var);
		body.addConnection(createDGet(atLeft), Helper.higherVar2LowerVar(paras));

	}

	protected abstract SyncBody createDGet(boolean atLeft);

	@Override
	public Collection<Var> getVarUsed(Collection<String> genericParas)
			throws EvaluationFailedException
	{
		Set<Var> result = new HashSet<Var>();
		result.add(_dict);
		result.add(_key);
		return result;
	}

}
